﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LuDo.PitEditor
{
    public partial class Opzioni : Form
    {
        public Opzioni()
        {
            InitializeComponent();         
        }

        private void Opzioni_Load(object sender, EventArgs e)
        {
            udImpegno.DataBindings.Add(new Binding("Value", PitEditor.Properties.Settings.Default, "ImpegnoSettimanale", true, DataSourceUpdateMode.OnPropertyChanged));
            udLordoQuota.DataBindings.Add(new Binding("Value", PitEditor.Properties.Settings.Default, "LordoQuota", true, DataSourceUpdateMode.OnPropertyChanged));
            udDimQuota.DataBindings.Add(new Binding("Value", PitEditor.Properties.Settings.Default, "DimensioneQuota", true, DataSourceUpdateMode.OnPropertyChanged));

            fontDialog.Font = PitEditor.Properties.Settings.Default.EditorFont;
            DescribeFont();
            cbCapoAutomatico.DataBindings.Add(new Binding("Checked", PitEditor.Properties.Settings.Default, "EditorWrapText", true, DataSourceUpdateMode.OnPropertyChanged));
            cmbReportPeriod.DataBindings.Add(new Binding("SelectedIndex", PitEditor.Properties.Settings.Default, "DefaultReportTimeIndex", true, DataSourceUpdateMode.OnPropertyChanged));

            txtOrigin.DataBindings.Add(new Binding("Text", PitEditor.Properties.Settings.Default, "SmtpOrigin", true, DataSourceUpdateMode.OnPropertyChanged));
            txtOriginDisplayName.DataBindings.Add(new Binding("Text", PitEditor.Properties.Settings.Default, "SmtpOriginName", true, DataSourceUpdateMode.OnPropertyChanged));
            txtDestination.DataBindings.Add(new Binding("Text", PitEditor.Properties.Settings.Default, "SmtpDestination", true, DataSourceUpdateMode.OnPropertyChanged));
            txtDestinationDisplayName.DataBindings.Add(new Binding("Text", PitEditor.Properties.Settings.Default, "SmtpDestinationName", true, DataSourceUpdateMode.OnPropertyChanged));
            txtServerName.DataBindings.Add(new Binding("Text", PitEditor.Properties.Settings.Default, "SmtpHost", true, DataSourceUpdateMode.OnPropertyChanged));
            udPort.DataBindings.Add(new Binding("Value", PitEditor.Properties.Settings.Default, "SmtpPort", false, DataSourceUpdateMode.OnPropertyChanged));
            cbInviaCopia.DataBindings.Add(new Binding("Checked", PitEditor.Properties.Settings.Default, "SmtpCopyToOrigin", true, DataSourceUpdateMode.OnPropertyChanged));
            txtSmtpUsername.DataBindings.Add(new Binding("Text", PitEditor.Properties.Settings.Default, "SmtpUserName", true, DataSourceUpdateMode.OnPropertyChanged));
            txtSmtpPassword.DataBindings.Add(new Binding("Text", PitEditor.Properties.Settings.Default, "SmtpPassword", true, DataSourceUpdateMode.OnPropertyChanged));
            txtSignature.DataBindings.Add(new Binding("Text", PitEditor.Properties.Settings.Default, "SmtpSignature", true, DataSourceUpdateMode.OnPropertyChanged));       
        }

        private void btnFont_Click(object sender, EventArgs e)
        {
            DialogResult res = fontDialog.ShowDialog();
            if (res == DialogResult.OK)
            {
                PitEditor.Properties.Settings.Default.EditorFont = fontDialog.Font; 
                DescribeFont();
            }
        }

        private void DescribeFont()
        {
            string description = String.Format("{0} {1}", fontDialog.Font.Name, fontDialog.Font.Size);
            txtFont.Text = description;
        }
    }
}
